from django import forms
from .models import Post, Comment


class PostForm(forms.ModelForm):
    """文章表单"""
    class Meta:
        model = Post
        fields = ['title', 'slug', 'content', 'excerpt', 'category', 'status']
        widgets = {
            'title': forms.TextInput(attrs={
                'class': 'form-control',
                'placeholder': '请输入文章标题'
            }),
            'slug': forms.TextInput(attrs={
                'class': 'form-control',
                'placeholder': 'URL别名（英文和数字）'
            }),
            'content': forms.Textarea(attrs={
                'class': 'form-control',
                'rows': 15,
                'placeholder': '请输入文章内容'
            }),
            'excerpt': forms.Textarea(attrs={
                'class': 'form-control',
                'rows': 3,
                'placeholder': '请输入文章摘要（可选）'
            }),
            'category': forms.Select(attrs={
                'class': 'form-control'
            }),
            'status': forms.Select(attrs={
                'class': 'form-control'
            }),
        }
        labels = {
            'title': '标题',
            'slug': 'URL别名',
            'content': '内容',
            'excerpt': '摘要',
            'category': '分类',
            'status': '状态',
        }


class CommentForm(forms.ModelForm):
    """评论表单"""
    class Meta:
        model = Comment
        fields = ['content']
        widgets = {
            'content': forms.Textarea(attrs={
                'class': 'form-control',
                'rows': 4,
                'placeholder': '请输入您的评论...'
            })
        }
        labels = {
            'content': '评论内容'
        }
